<?php
// .-----------------------------------------------------------------------------------
// | WE TRY THE BEST WAY
// |-----------------------------------------------------------------------------------
// | Author: 贝贝 <hebiduhebi@163.com>
// | Copyright (c) 2013-2015, http://www.gooraye.net. All Rights Reserved.
// |-----------------------------------------------------------------------------------

namespace Ucenter\Api;

use Ucenter\Model\MemberModel;

class MemberApi extends \Common\Api\Api{

	const ADD            = "Ucenter/Member/add";
	const GET_INFO       = "Ucenter/Member/getInfo";

	const RAISE_SCORE    = "Ucenter/Member/raiseScore";
	const DECREASE_SCORE = "Ucenter/Member/decreaseScore";


	//初始化
	protected function _init(){
		$this->model = new MemberModel();
	}

	public function raiseScore($uid,$score){

		$map = array(
			'uid' => $uid,
		);

		$result = $this -> model -> where($map) -> setInc('score',$score);

		if($result === false){
			$error = $this -> model -> getDbError();
			return $this -> apiReturnErr($error);
		}else{
			return $this -> apiReturnSuc($result);
		}

	}

	/**
	 * 减去用户积分
	 * @param $uid
	 * @param $score 输入为正数
	 */
	public function decreaseScore($uid,$score){
		$map = array(
				'uid' => $uid,
		);

		$result = $this -> model -> where($map) -> setDec('score',$score);
		if($result === false){
			$error = $this -> model -> getDbError();
			return $this -> apiReturnErr($error);
		}else{
			return $this -> apiReturnSuc($result);
		}
	}

	public function queryByGroup($map,$page){
		$result = $this->model->queryByGroup($map,$page);
		if($result === false){
			return $this->apiReturnErr($this->model->getDbError());
		}else{
			return $this->apiReturnSuc($result);
		}
	}
}
